package com.framework.plm.bas.param;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.framework.plm.bas.util.PlmBasConstant;
import com.framework.plm.sec.vo.LogonUserObject;

@SuppressWarnings("unchecked")
public class GeneralParam implements Serializable {

	private static final long serialVersionUID = 1L;

	private static ThreadLocal<GeneralParam> thgp = new ThreadLocal<GeneralParam>();
	
	private Map map = new HashMap();
	private HttpServletRequest request=null;
	
	public static GeneralParam getCurrent(){
		GeneralParam gp = thgp.get();
		if(gp == null){
			gp = GeneralParam.getInstance();
			thgp.set(gp);
		}
		return gp;
	}
	public static void clear(){
		thgp.set(null);
	}

	private GeneralParam(){
		
	}
	/**
	 * 获取实例。
	 * @return
	 */
	private static GeneralParam getInstance() {
		return new GeneralParam();
	}

	public Map getValueMap() {
		return map;
	}

	public BigDecimal getValueBigDecimal(Object key) {
		return (BigDecimal) map.get(key);
	}

	public Class getValueClass(Object key) {
		return (Class) map.get(key);
	}

	public Integer getValueInteger(Object key) {
		return (Integer) map.get(key);
	}

	public Long getValueLong(Object key) {
		return (Long) map.get(key);
	}

	public Object getValueObject(Object key) {
		return map.get(key);
	}

	public String getValueString(Object key) {
		return (String) map.get(key);
	}

	public Object setValue(Object key, Object value) {
		map.put(key, value);
		return this;
	}

	public Object setValue(Map values) {
		map.putAll(values);
		return this;
	}

	/**
	 * 取得当前交易的交易码。
	 * @return
	 */
	public String getAppService() {
		Object obj = map.get(PlmBasConstant.APP_SERVICE);
		return obj == null ? null : (String) obj;
	}
	
	public void setAppService(String code) {
		map.put(PlmBasConstant.APP_SERVICE, code);
	}
	
	public HttpServletRequest getRequest(){
		return this.request;
	}
	public void setRequest(HttpServletRequest request){
		this.request = request;
	}
	
	/**
	 * 取得当前交易的用户对象。
	 * @return
	 */
	public LogonUserObject getAppUser() {
		Object obj = map.get(PlmBasConstant.APP_USER);
		return obj == null ? null : (LogonUserObject) obj;
	}

	/**
	 * 取得当前查询码。
	 * @return
	 */
	public String getAppValidId() {
		Object obj = map.get(PlmBasConstant.APP_VALID_ID);
		return obj == null ? null : (String) obj;
	}
}
